<!DOCTYPE html>
<html>
<head>
<title>The custom element prototype must be set just prior to invoking created callback</title>
<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="The custom element prototype must be set just prior to invoking callback.">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#types-of-callbacks">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script>
test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();

    doc.body.innerHTML = '<x-a></x-a>';
    doc.registerElement('x-a', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'in HTML before registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();

    doc.registerElement('x-b', {prototype: proto});
    doc.body.innerHTML = '<x-b></x-b>';
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'in HTML after registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var customElement = doc.createElement('x-c');

    doc.body.appendChild(customElement);
    doc.registerElement('x-c', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via document.createElement() before registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-d', {prototype: proto});

    var customElement = doc.createElement('x-d');
    doc.body.appendChild(customElement);
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via document.createElement() after registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var GeneratedConstructor = doc.registerElement('x-e', {prototype: proto});
    var customElement = new GeneratedConstructor();

    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via constructor returned by method registerElement');


testInIFrame('../../resources/x-element.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-element', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'by UA parser before registration of a custom element');
</script>
</body>
</html>
